struct ip_mreq mreq;
struct sockaddr_in maddr;
int sock;
+ char errmsg[] =
+ "udpConf fileId [-mcastadd] [-mcastdrop] groupaddr | "
+ "udpConf fileId remotehost remoteport | "
+ "udpConf fileId [-myport] [-remote] [-peer] [-broadcast] [-ttl]";
if (argc != 4 && argc != 3) {
- result = "udpConf fileId [-mcastadd] [-mcastdrop] groupaddr | udpConf fileId remotehost remoteport | udpConf fileId [-myport] [-remote] [-peer] [-broadcast]";
- Tcl_SetResult (interp, result, NULL);
+ Tcl_SetResult (interp, errmsg, NULL);
return TCL_ERROR;
}
chan = Tcl_GetChannel(interp, (char *)argv[1], NULL);
socklen_t optlen = sizeof(int);
if (getsockopt(statePtr->sock, SOL_SOCKET, SO_BROADCAST,
(char *)&tmp, &optlen)) {
- sprintf(errBuf, "%s", "udp - setsockopt");
- UDPTRACE("UDP error - setsockopt\n");
+ sprintf(errBuf, "%s", "udp - getsockopt");
+ UDPTRACE("UDP error - getsockopt\n");
+ Tcl_AppendResult(interp, errBuf, (char *)NULL);
+ return TCL_ERROR;
+ } else {
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(tmp));
+ return TCL_OK;
+ }
+ } else if (!strcmp(argv[2], "-ttl")) {
+ int tmp = 1;
+ socklen_t optlen = sizeof(int);
+ if (getsockopt(statePtr->sock, SOL_IP, IP_TTL,
+ (char *)&tmp, &optlen)) {
+ sprintf(errBuf, "%s", "udp - getsockopt");
+ UDPTRACE("UDP error - getsockopt\n");
Tcl_AppendResult(interp, errBuf, (char *)NULL);
return TCL_ERROR;
} else {
return TCL_OK;
}
} else {
- result = "udpConf fileId [-mcastadd] [-mcastdrop] groupaddr | udpConf fileId remotehost remoteport | udpConf fileId [-myport] [-remote] [-peer]";
- Tcl_SetResult (interp, result, NULL);
+ Tcl_SetResult (interp, errmsg, NULL);
return TCL_ERROR;
}
return TCL_OK;
}
}
return r;
+ } else if (!strcmp(argv[2], "-ttl")) {
+ socklen_t optlen = sizeof(int);
+ int tmp = 0;
+ int r = Tcl_GetInt(interp, argv[3], &tmp);
+ if (r == TCL_OK) {
+ if (setsockopt(statePtr->sock, SOL_IP, IP_TTL,
+ (const char *)&tmp, optlen)) {
+ sprintf(errBuf, "%s", "udp - setsockopt");
+ UDPTRACE("UDP error - setsockopt\n");
+ Tcl_AppendResult(interp, errBuf, (char *)NULL);
+ r = TCL_ERROR;
+ } else {
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(tmp));
+ }
+ }
+ return r;
} else {
if (strlen(argv[2]) >= sizeof(statePtr->remotehost)) {
result = "hostname too long";
return udpGetService(interp, argv[3], &(statePtr->remoteport));
}
} else {
- result = "udpConf fileId [-mcastadd] [-mcastdrop] groupaddr | udpConf fileId remotehost remoteport | udpConf fileId [-myport] [-remote] [-peer]";
- Tcl_SetResult (interp, result, NULL);
+ Tcl_SetResult (interp, errmsg, NULL);
return TCL_ERROR;
}
}
CONST84 char *optionName, Tcl_DString *optionValue)
{
UdpState *statePtr = (UdpState *)instanceData;
- CONST84 char * options = "myport remote peer mcastadd mcastdrop";
+ CONST84 char * options = "myport remote peer mcastadd mcastdrop broadcast ttl";
int r = TCL_OK;
if (optionName == NULL) {
udpGetOption(instanceData, interp, "-mcastdrop", optionValue);
Tcl_DStringAppend(optionValue, " -broadcast ", -1);
udpGetOption(instanceData, interp, "-broadcast", optionValue);
+ Tcl_DStringAppend(optionValue, " -ttl ", -1);
+ udpGetOption(instanceData, interp, "-ttl", optionValue);
} else {
socklen_t optlen = sizeof(int);
if (getsockopt(statePtr->sock, SOL_SOCKET, SO_BROADCAST,
(char *)&tmp, &optlen)) {
- UDPTRACE("UDP error - setsockopt\n");
- Tcl_SetResult(interp, "error in setsockopt", TCL_STATIC);
+ UDPTRACE("UDP error - getsockopt\n");
+ Tcl_SetResult(interp, "error in getsockopt", TCL_STATIC);
r = TCL_ERROR;
} else {
Tcl_DStringSetLength(&ds, TCL_INTEGER_SPACE);
sprintf(Tcl_DStringValue(&ds), "%d", tmp);
}
+ } else if (!strcmp("-ttl", optionName)) {
+
+ unsigned int tmp = 0;
+ socklen_t optlen = sizeof(unsigned int);
+ if (getsockopt(statePtr->sock, SOL_IP, IP_TTL,
+ (char *)&tmp, &optlen)) {
+ UDPTRACE("UDP error - getsockopt");
+ Tcl_SetResult(interp, "error in getsockopt", TCL_STATIC);
+ r = TCL_ERROR;
+ } else {
+ Tcl_DStringSetLength(&ds, TCL_INTEGER_SPACE);
+ sprintf(Tcl_DStringValue(&ds), "%u", tmp);
+ }
+
} else {
r = Tcl_BadChannelOption(interp, optionName, options);
}
CONST84 char *optionName, CONST84 char *newValue)
{
UdpState *statePtr = (UdpState *)instanceData;
- CONST84 char * options = "remote mcastadd mcastdrop broadcast";
+ CONST84 char * options = "remote mcastadd mcastdrop broadcast ttl";
int r = TCL_OK;
if (!strcmp("-remote", optionName)) {
Tcl_SetObjResult(interp, Tcl_NewIntObj(tmp));
}
}
+ } else if (!strcmp("-ttl", optionName)) {
+
+ unsigned int tmp = 0;
+ r = Tcl_GetInt(interp, newValue, &tmp);
+ if (r == TCL_OK) {
+ if (setsockopt(statePtr->sock, SOL_IP, IP_TTL,
+ (const char *)&tmp, sizeof(unsigned int))) {
+ sprintf(errBuf, "udp - setsockopt ttl");
+ UDPTRACE("UDP error - setsockopt\n");
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(errBuf, -1));
+ r = TCL_ERROR;
+ } else {
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(tmp));
+ }
+ }
} else {