[12] in 6.033-lab
Re: bind_service woes
daemon@ATHENA.MIT.EDU (Constantine P. Sapuntzakis)
Sun Mar 16 09:47:57 1997
To: "Kevin 'Bob' Fu" <fubob@MIT.EDU>
Cc: 6.033-lab@MIT.EDU
In-Reply-To: Your message of "Sat, 15 Mar 1997 19:35:19 EST."
<9703160035.AA09728@gaston.MIT.EDU>
Date: Sun, 16 Mar 1997 09:47:43 EST
From: "Constantine P. Sapuntzakis" <csapuntz@MIT.EDU>
> I've been working on this problem all day. Can you shed any light on
> this problem? I consistently get a segfault on the bind call:
>
> SVCDAT *bind_service (const struct sockaddr *service_addr)
> {
> SVCDAT *svc;
> int s;
>
> /* Use UDP transport */
> if ((s=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
> return (SVCDAT *) NULL;
> {
> int n = 1;
> if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof (n)) <0)
> return (SVCDAT *) NULL;
> }
>
> if (bind(s, (struct sockaddr *)service_addr, sizeof(struct sockaddr))<0)
> return (SVCDAT *) NULL;
> ....
>
Looks like you're passing the wrong length into bind. The length of the
structure is actually sizeof (struct sockaddr_in). The way to solve this
is to modify bind_service so we pass the length of the sockaddr structure:
SVCDAT *bind_service(struct sockaddr *service, int len)
-Costa
csapuntz@mit.edu