SCTP Discussions

Text archives Help


[SCTP-Discussion] Discard example and modified sctp.h


Chronological Thread 
  • From: Michael Tüxen <Michael.Tuexen AT micmac.franken.de>
  • To: <discussion AT sctp.de>, Andreas Jungmaier <ajung AT exp-math.uni-essen.de>
  • Subject: [SCTP-Discussion] Discard example and modified sctp.h
  • Date: Fri Feb 23 22:33:04 2001
  • List-id: SCTP Discussions <discussion.sctp.de>

Dear all,

please find attached an example for a discard server. It simply discards
all packets and
displays all notifications.

Andreas, I have modified the sctp.h file.

I changed

unsigned char * xxx[]

to

unsigend char xxx[]

in severeal function prototypes, which is hopefully what you mean? Am i right?

I also changed

unsigned char *primaryDestinationAddress[]

to

unsigned char *primaryDestinationAddress

and the same with similiar other fields in structures. My compiler
complains about the first one and I think you ment the second. Right?

A last comment: Why is the length parameter of sctp_receive a pointer?
Shouldn't it be the length of the buffer?

Best regards
Michael

--
e-mail:
Michael.Tuexen AT micmac.franken.de

Attachment: sctp.h
Description: Binary data

/* * $Id: discard_server.c,v 1.2 2001/02/15 17:45:07 ajung Exp $ * * SCTP implementation according to RFC 2960. * Copyright (C) 2000 by Siemens AG, Munich, Germany. * * Realized in co-operation between Siemens AG * and University of Essen, Institute of Computer Networking Technology. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * There are two mailinglists available at http://www.sctp.de which should be * used for any discussion related to this implementation. * * Contact: discussion AT sctp.de * Michael.Tuexen AT icn.siemens.de * ajung AT exp-math.uni-essen.de * * discard_server.c - main program module * * This is a 'minimal' implementation of a server. It discards all packets * it is receiving. Only a verbose mode is supported. */ #include "sctp.h" #include #include #define DISCARD_PORT 9 #define MAXIMUM_NUMBER_OF_LOCAL_ADDRESSES 10 #define MAXIMUM_PAYLOAD_LENGTH 1500 #define MAXIMUM_NUMBER_OF_IN_STREAMS 17 #define MAXIMUM_NUMBER_OF_OUT_STREAMS 1 static unsigned char localAddressList[MAXIMUM_NUMBER_OF_LOCAL_ADDRESSES][MAX_IP_LEN]; static unsigned short noOfLocalAddresses = 0; static int verbose = 0; static int vverbose = 0; void getArgs(int argc, char **argv) { int c; extern char *optarg; extern int optind; while ((c = getopt(argc, argv, "s:vV")) != -1) { switch (c) { case 's': if ((noOfLocalAddresses < MAXIMUM_NUMBER_OF_LOCAL_ADDRESSES) && (strlen(optarg) < MAX_IP_LEN )) { strcpy(localAddressList[noOfLocalAddresses], optarg); noOfLocalAddresses++; }; break; case 'v': verbose = 1; break; case 'V': verbose = 1; vverbose = 1; break; } } } void dataArriveNotif(unsigned int assoc_id, unsigned int stream_id, unsigned int len, unsigned int protoID, unsigned int unordered, void* dummy) { unsigned char chunk[MAXIMUM_PAYLOAD_LENGTH]; int length; if (vverbose) { fprintf(stdout, "%-8u: Data arrived (%u bytes on stream %u, %s)\n", assoc_id, len, stream_id, (unordered==ORDERED_DELIVERY)?"ordered":"unordered"); fflush(stdout); }; /* read and discard it */ sctp_receive(assoc_id, stream_id, chunk, (unsigned int *) &length); } void sentFailureNotif(unsigned int assoc_id, unsigned char *unsent_data, unsigned int data_len, unsigned int *context, void* dummy) { if (verbose) { fprintf(stdout, "%-8u: Sent failure\n", assoc_id); fflush(stdout); } } void networkStatusChangeNotif(unsigned int assoc_id, short dest_add, unsigned short new_state, void* dummy) { if (verbose) { fprintf(stdout, "%-8u: Network status change: path %u is now %s\n", assoc_id, dest_add, ((new_state == PATH_OK) ? "ACTIVE" : "INACTIVE")); fflush(stdout); } } void* communicationUpNotif(unsigned int assoc_id, unsigned short status, unsigned char destinations[][], int noOfDestinations, unsigned short noOfInStreams, unsigned short noOfOutStreams, void* dummy) { if (verbose) { fprintf(stdout, "%-8u: Communication up (%u paths)\n", assoc_id, noOfDestinations); fflush(stdout); } /* use no upper layer identifier */ return NULL; } void communicationLostNotif(unsigned int assoc_id, unsigned short status, void* dummy) { if (verbose) { fprintf(stdout, "%-8u: Communication lost (status %u)\n", assoc_id, status); fflush(stdout); }; /* delete the association */ sctp_delete_association(assoc_id); } void communicationErrorNotif(unsigned int assoc_id, unsigned short status, void* dummy) { if (verbose) { fprintf(stdout, "%-8u: Communication error (status %u)\n", assoc_id, status); fflush(stdout); } } void restartNotif(unsigned int assoc_id, void* dummy) { if (verbose) { fprintf(stdout, "%-8u: Restart\n", assoc_id); fflush(stdout); } } void shutdownCompleteNotif(unsigned int assoc_id, void* dummy) { if (verbose) { fprintf(stdout, "%-8u: Shutdown complete\n", assoc_id); fflush(stdout); } } int main(int argc, char **argv) { unsigned short sctp_instance; struct ULPcallback discard_ulp; /* initialize the discard_ulp variable */ discard_ulp.dataArriveNotif = &dataArriveNotif; discard_ulp.sentFailureNotif = &sentFailureNotif; discard_ulp.networkStatusChangeNotif = &networkStatusChangeNotif; discard_ulp.communicationUpNotif = &communicationUpNotif; discard_ulp.communicationLostNotif = &communicationLostNotif; discard_ulp.communicationErrorNotif = &communicationErrorNotif; discard_ulp.RestartNotif = &restartNotif; discard_ulp.ShutdownCompleteNotif = &shutdownCompleteNotif; /* handle all command line options */ getArgs(argc, argv); /* set up the "server" */ sctp_instance = sctp_registerSCTP_instance(DISCARD_PORT, MAXIMUM_NUMBER_OF_IN_STREAMS, MAXIMUM_NUMBER_OF_OUT_STREAMS, noOfLocalAddresses, localAddressList, discard_ulp); /* run the event handler forever */ while (sctp_event_loop() >= 0); /* this will never be reached */ return 0; }

  • [SCTP-Discussion] Discard example and modified sctp.h, Michael Tüxen, 02/23/2001

Archive powered by MHonArc 2.6.19+.

Top of page