Article View: comp.sys.sun
Article #11759SUN 386i bind() problem
From: mrevox!rwu
Date: Thu, 30 Mar 1989 02:33
Date: Thu, 30 Mar 1989 02:33
66 lines
2293 bytes
2293 bytes
Has anyone run into problems with the bind() call on the SUN 386i? I have
a program which runs fine on a SUN 4 under 4.0.1 but fails on the 386i
under 4.0.1. I create an internet stream socket successfully, but then the
subsequent bind call fails with an error return of EADDRNOTAVAIL. Any
ideas as to what I might be doing wrong?
The offending section of code is attached below.
Ron Underwood
UUCP: bellcore!rwu
ARPA: rwu@bellcore.com
(201) 829-3317
Bell Communications Research
435 South St. Room 2D-392
Morristown, NJ 07960-1961
__________
main()
{
struct servent *service;
struct protoent *protocol;
struct sockaddr_in name;
struct sockaddr_in conn;
int s,ns,pn,connlen;
if (fork())
exit(0);
signal (SIGCHLD, reapchild);
for (s = 0; s < 20; s++)
(void)close(s);
(void)open("/", 0);
(void)dup2(0, 1);
(void)dup2(0, 2);
if ((s=open("/dev/tty", 2)) >= 0) {
(void)ioctl(s, TIOCNOTTY, (char *)0);
(void)close(s);
}
logfile = fopen(LOGFILE,"a");
if(access(HISTORY,R_OK) == -1){
logmsg(errno,"Can't access history file");
exit(1);
}
service = getservbyname("rnews","tcp");
if(service == NULL){
logmsg(0,"Unknown service");
exit(1);
}
protocol = getprotobyname(service->s_proto);
if(protocol == NULL){
logmsg(0,"Unknown protocol %s",service->s_proto);
exit(1);
}
pn = protocol->p_proto;
s = socket(AF_INET,SOCK_STREAM,pn);
if(s == -1){
logmsg(errno,"Cannot create service socket");
exit(1);
}
name.sin_port = service->s_port;
if(bind(s,(struct sockaddr_in *)&name,sizeof(name)) == -1){
logmsg(errno,"Socket bind failed");
exit(1);
}
[[ You need to "bzero(&name, sizeof(name));" before using it! If it
worked on a Sun 4 then it was luck. --wnl ]]
Technical Details
Message-ID:
<25900002@mrevox.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!rice!sun-spots-requestShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!rice!sun-spots-request From: mrevox!rwu@bellcore.bellcore.com Newsgroups: comp.sys.sun Subject: SUN 386i bind() problem Keywords: Software Message-ID: <25900002@mrevox.UUCP> Date: 30 Mar 89 02:33:30 GMT Sender: usenet@rice.edu Organization: Bell Communications Research, Inc. Lines: 66 Approved: Sun-Spots@rice.edu Original-Date: 10 Mar 89 21:37:00 GMT X-Sun-Spots-Digest: Volume 7, Issue 213, message 10 of 15