int i;
for (i=0; socket_options[i].name != NULL; i++) {
- const smb_socket_option *opt = &socket_options[i];
+ const smb_socket_option *p = &socket_options[i];
int value = 0;
socklen_t vlen = sizeof(value);
int ret;
- if (!strequal(opt->name, option)) {
+ if (!strequal(p->name, option)) {
continue;
}
- ret = getsockopt(fd,
- opt->level,
- opt->option,
- (void *)&value,
- &vlen);
+ ret = getsockopt(fd, p->level, p->option,
+ (void *)&value, &vlen);
if (ret == -1) {
return -1;
}
return -1;
}
-void set_socket_option(int fd, const char *option)
-{
- TALLOC_CTX *frame = talloc_stackframe();
- char *name = NULL;
- int value = 1;
- char *p = NULL;
- bool got_value = false;
- int i;
-
- name = talloc_strdup(frame, option);
- if (name == NULL) {
- DEBUG(0,("talloc_strdup(%s) - failed\n", option));
- TALLOC_FREE(frame);
- return;
- }
+/****************************************************************************
+ Set user socket options.
+****************************************************************************/
- if ((p = strchr_m(name, '='))) {
- *p = 0;
- value = atoi(p+1);
- got_value = true;
- }
+void set_socket_options(int fd, const char *options)
+{
+ TALLOC_CTX *ctx = talloc_new(NULL);
+ char *tok;
+
+ while (next_token_talloc(ctx, &options, &tok," \t,")) {
+ int ret=0,i;
+ int value = 1;
+ char *p;
+ bool got_value = false;
+
+ if ((p = strchr_m(tok,'='))) {
+ *p = 0;
+ value = atoi(p+1);
+ got_value = true;
+ }
- for (i=0; socket_options[i].name != NULL; i++) {
- const smb_socket_option *opt = &socket_options[i];
- int ret;
+ for (i=0;socket_options[i].name;i++)
+ if (strequal(socket_options[i].name,tok))
+ break;
- if (!strequal(opt->name, name)) {
+ if (!socket_options[i].name) {
+ DEBUG(0,("Unknown socket option %s\n",tok));
continue;
}
- switch (opt->opttype) {
+ switch (socket_options[i].opttype) {
case OPT_BOOL:
case OPT_INT:
+ ret = setsockopt(fd,socket_options[i].level,
+ socket_options[i].option,
+ (char *)&value,sizeof(int));
break;
+
case OPT_ON:
- if (got_value) {
+ if (got_value)
DEBUG(0,("syntax error - %s "
- "does not take a value\n",
- option));
- }
+ "does not take a value\n",tok));
- value = opt->value;
+ {
+ int on = socket_options[i].value;
+ ret = setsockopt(fd,socket_options[i].level,
+ socket_options[i].option,
+ (char *)&on,sizeof(int));
+ }
break;
- default:
- continue;
}
- ret = setsockopt(fd,
- opt->level,
- opt->option,
- (char *)&value,
- sizeof(int));
if (ret != 0) {
/* be aware that some systems like Solaris return
* EINVAL to a setsockopt() call when the client
* sent a RST previously - no need to worry */
DEBUG(2,("Failed to set socket option %s (Error %s)\n",
- option, strerror(errno) ));
+ tok, strerror(errno) ));
}
- TALLOC_FREE(frame);
- return;
- }
-
- DEBUG(0,("Unknown socket option %s\n", option));
- TALLOC_FREE(frame);
-}
-
-/****************************************************************************
- Set user socket options.
-****************************************************************************/
-
-void set_socket_options(int fd, const char *options)
-{
- TALLOC_CTX *frame = talloc_stackframe();
- char *tok = NULL;
-
- while (next_token_talloc(frame, &options, &tok," \t,")) {
- set_socket_option(fd, tok);
}
+ TALLOC_FREE(ctx);
print_socket_options(fd);
- TALLOC_FREE(frame);
}
#define GET_SOCK_OPT(_fd, _name) \
#define SET_SOCK_OPT(_fd, _name, _value) do { \
char _val[100]; \
snprintf(_val, sizeof(_val) - 1, #_name "=%d", _value); \
- set_socket_option(_fd, _val); \
+ set_socket_options(_fd, _val); \
} while(0)
void set_socket_options_keepalive(int sock_fd,