AW: [En-Nut-Discussion] Problem to send data with an UDP socket
Ernst Stippl
ernst at stippl.org
Tue Jul 5 21:22:09 CEST 2005
Hi Julien!
Here is a code snippet which works for me:
u_char send_snmp (u_long remoteaddr, u_char len)
{
UDPSOCKET *udp_sock;
u_short remoteport;
u_long *pRemoteaddr;
u_short *pRemoteport;
u_short writelen;
u_short readlen;
u_long timeout;
u_short localport;
u_short r;
u_char *resultstring;
remoteport = 161;
writelen = len;
timeout = 10000;
pRemoteaddr = &remoteaddr;
pRemoteport = &remoteport;
readlen = 0;
localport = 0;
udp_sock = NutUdpCreateSocket(localport); // create socket
if (udp_sock != 0)
IF_LOG_SNMP printf("SNMP: UDP Socket port %d\n",
udp_sock->so_local_port);
// SNMP request Send an UDP datagram.
r = NutUdpSendTo ( udp_sock, remoteaddr, remoteport, SNMP_buff, writelen);
.....
I use this to create the udp packets to carry snmp requests, and it works.
Make sure the IP connection is active by pinging the Ethernut and use a
program like Ethereal to trace whats on the wire.
hope this helps
ernst
-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von Julien CHAUSSEC
Gesendet: Dienstag, 05. Juli 2005 11:40
An: en-nut-discussion at egnite.de
Betreff: [En-Nut-Discussion] Problem to send data with an UDP socket
Hi everybody,
When i want to send data, with the function NutUdpSendTo(), the returned
data (rt) is -1. I use avr gcc. All the functions called before are OK. Sock
gives the value 2934 and rc gives 0 the first and the second time.
There is enough memory availiable (NutHeapAvailable() ).
Here is the code i use:
int rc = NutRegisterDevice(&DEV_ETHER, 0x8300, 5); u_long ip_addr =
inet_addr(STDNET_IPADDR); u_long ip_mask = inet_addr(STDNET_IPMASK); rc =
NutNetIfConfig("eth0", null_mac, ip_addr,ip_mask);
UDPSOCKET *sock;
sock = NutUdpCreateSocket(10999);
printf("nombre d'octets disponible=%d\n\r", mem);
char tab [50];
int rt;
for (;;)
{
rt = NutUdpSendTo(sock, inet_addr("134.246.255.255"),
13020,tab,strlen(tab));
NutSleep(1000);
}
}
Does anyone have an idea?
Thank you.
Julien.Chaussec at ifremer.fr
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
More information about the En-Nut-Discussion
mailing list