*BSD News Article 86194


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mira.net.au!vic.news.telstra.net!news.telstra.net!news-out.internetmci.com!dciteleport.com!feed1.news.erols.com!howland.erols.net!news.nacamar.de!nntp.uio.no!nntp-oslo.UNINETT.no!nntp-trd.UNINETT.no!not-for-mail
From: sthaug@nethelp.no (Steinar Haug)
Newsgroups: comp.unix.programmer,comp.unix.bsd.freebsd.misc
Subject: Re: UDP Sockets sendto() failures
Followup-To: comp.unix.programmer,comp.unix.bsd.freebsd.misc
Date: 04 Jan 1997 11:34:54 GMT
Organization: Nethelp Consulting, Trondheim, Norway
Lines: 20
Message-ID: <5alf8u$rdp@verdi.nethelp.no>
References: <E3DxuK.6I8@netplex-tech.com> <E3H7yK.18t@netplex-tech.com>
NNTP-Posting-Host: aun.uninett.no
In-reply-to: vikas@netplex-tech.Com's message of Sat, 4 Jan 1997 09:06:19 GMT
Xref: euryale.cc.adfa.oz.au comp.unix.programmer:48354 comp.unix.bsd.freebsd.misc:33604

[Vikas Aggarwal]

|   Since a number of people have suggested that it is more likely that I
|   have a bug in my code, I am posting my code below.

I think you do - a missing htons() for the port number.

|   send_udpmesg(buf, bufsize, dgramfd, host, port)

. is called with port number in host order.

|     bzero(&dest_addr_in, sizeof(dest_addr_in));
|     dest_addr_in.sin_family = AF_INET;
|     dest_addr_in.sin_addr.s_addr = inet_addr(desthost);
|     dest_addr_in.sin_port = port;

. and here you stuff it into the sockaddr_in, still in host order.
You need a htons() here.

Steinar Haug, Nethelp consulting, sthaug@nethelp.no