From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,d1bdd99423d805c7,start X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1993-05-30 13:21:29 PST Path: gmd.de!rrz.uni-koeln.de!unidui!math.fu-berlin.de!news.dfn.de!scsing.switch.ch!news.univie.ac.at!paladin.american.edu!howland.reston.ans.net!ux1.cso.uiuc.edu!uwm.edu!opus.csd.uwm.edu!dave From: dave@csd4.csd.uwm.edu (Dave Rasmussen) Newsgroups: comp.unix.osf.osf1 Subject: Alpha/OSF network code question Date: 30 May 1993 19:19:53 GMT Organization: UW-Milwaukee Computing Services Division Distribution: na Message-ID: <1ub1cpINNgpb@uwm.edu> NNTP-Posting-Host: 129.89.70.40 Originator: dave@opus.csd.uwm.edu I've been looking at this code a while now and can't figure out what conversion I need to do to the port I get from the getservbyname in order to bind a name to the proper socket. Any advice to this or anything else I'm doing would be appreciated. I have the appropriate entry in the services file by the way. Running netstat, I can't seem to get it to connect to the port I have defined in services. /* * Some test server daemon code */ #include #include #include #include main (argc,argv) int argc; char **argv; /* standard unix arguments */ { struct sockaddr_in sa; /*addresses for sockets*/ struct servent *sp; /* service entry from /etc/services */ struct hostent *hp; /* host name entry */ char hostnm[40]; int ss; /* for socket */ unsigned short htons(); (void) gethostname(hostnm,40 ); if ((hp = gethostbyname(hostnm)) == NULL) { perror("gethostbyname"); exit(1); } sp = getservbyname("testsd", "tcp"); if (sp == NULL) { fprintf (stderr, "testsd: testsd/tcp unknown service\n"); exit (-1); } /* * set up port number for socket address */ sa.sin_port = htons(sp->s_port); /* what conversion should I use here??? */ sa.sin_family = hp->h_addrtype; fprintf(stderr,"service=%s\n",sp->s_name); fprintf(stderr,"htons(%d)=%d\n",sp->s_port,htons(sp->s_port)); printf("%d %d %d %d\n",hp->h_addr[0],hp->h_addr[1],hp->h_addr[2],hp->h_addr[3]); bcopy((unsigned char *)hp->h_addr,(unsigned char *)&sa.sin_addr,hp->h_length); if ((ss = socket(hp->h_addrtype,SOCK_STREAM,0)) < 0){ perror("socket"); exit(1); } printf("now to do the hinder binder\n"); /* * bind socket to port number */ if (bind (ss, &sa, sizeof sa) < 0 ){ fprintf(stderr, "testsd: server socket bind failed - server down\n"); perror("testsd_bind"); exit (-1); } getchar(); /* here just for me shove it in the background and see what's going on */ } -- Dave Rasmussen - SysAdm/Hacker/Consulting Manager, UWM Computing Svcs Div. Internet:dave@uwm.edu, Uucp:uwm!dave, Bitnet:dave%uwm.edu@INTERBIT AT&T:414-229-5133 USmail:Box 413 EMS380,Milwaukee,WI 53201 HAM: N9REJ