Subject: setting the ttl (in winsock2)

From: John Daniel Rosenberry <[email-masked]>
Date: Wed, 14 Aug 1996 14:40:31 -0400 (EDT)

my sysadmin suggested sending this query here.

i sent it off to the winsock-2 mailing list and got bonehead answers
  (use setsockopt(theSocket,IP_PROTO, IP_TTL /*duh (IP_MULTICAST_TTL)*/,
&ttl,                               sizeof(int)/*and again
(sizeof(char))*/)
   this doesn't work under macrosuck's implementation (limitations) 
  )

any suggestions would be greatly appriciated (solutions even more)

thanks in advance
-dan

------------------msg begin
i am having difficulty setting the ttl on a packet.  was wondering if
anyone has had more success than i.

here is a code segment (minus error checking and startup/cleanup code)
showing what i have been trying.

/***************** BEGIN CODE *****************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>

#define HELLO_GROUP "225.0.0.37"
#define HELLO_PORT 12345
#define BUFSIZE 255

extern void load_data(char *buf,int size);

void main(void)
/*
 * this is a work around to sending messages to a multicast group as      
 * WSAJoinGroup() is not yet functional (at least in my version ogf the SDK).
 * hence i have need to set the ttl (note i do not need to recieve any data
 * from the multicast ip...   only send out a message.
 * if there is a more recent version of the SDK available in which
 * WSAJoinGroup() works, i would appriciate a pointer to it's location.
 * otherwise if someone could show me where i've gone wrong here, i would
 * greatly appriciate it.
 * thanks
 */
{    
  struct sockaddr_in addr;
  unsigned long nbytes;
  char ttl;
  WSABUF msg_data = {BUFSIZE,malloc(BUFSIZE)}
  char *data_buf = msg_data.buf;

  SOCKET theSocket = WSASocket(AF_INET, SOCK_DGRAM, 0, NULL, 0,         
                          WSA_FLAG_MULTIPOINT_C_LEAF |
WSA_FLAG_MULTIPOINT_D_LEAF);
  
  metset(&addr,0,sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr(HELLO_GROUP);
  addr.sin_port = htons(HELLO_PORT);

  ttl = 15; 
  WSAIoctl(theSocket, SIO_MULTICAST_SCOPE, (void *)&ttl, sizeof(ttl),   
                                  (void *)data_buf, BUFSIZE, &nbytes,
NULL, NULL);  
  /* at this point
   * WSAGetLastError() == 10022 == WSAEINVAL
   */
  
  load_data(dat_buf, BUFSIZE);
  WSASendTo(theSocket, &msg_data, 1, &nbytes, 0, (struct sockaddr *
)&addr,                                                                 
  NULL, NULL);
}

/****************** END CODE ******************/
thanks
-dan 
--------
To unsubscribe from this mailing list, send email to:
[email-masked]
Leave subject blank, and place the following in the body:
unsubscribe winsock-2 <your email address>
The email address you supply must be exactly the one majordomo uses for you.

---

From: Dave Rubin <[email-masked]>
Date: Wed, 14 Aug 1996 16:13:02 -0400

>   this doesn't work under macrosuck's implementation (limitations) 

You need to bind() to a local address (INADDR_ANY) before you can set any options on the socket.

--
Dave Rubin
Netcast Communications Corporation
[email-masked]