I was writing a simple C server and experimenting with setsockopt, so I wrote the following:
int lsock = socket(AF_INET, SOCK_STREAM, 0);
int mss = 576;
if (setsockopt(lsock, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss)) != 0) {
perror("setsockopt");
return 1;
}
However, this code failed with the following error:
setsockopt: Invalid argument
According to the man page, setsockopt sets errno to EINVAL in two cases:
- The option is invalid at the level indicated.
- The socket has been shut down.
Neither case applies here, so what am I doing wrong?
int? I wasn't aware that any did. Or are you perhaps thinking of 64-bitlong?u_int32_tyour own typedef? It's not one of those defined bystdint.h(though there isuint32_t, which might be what you meant).TCP_MAXSEGoption for your socket viagetsockopt()? That speaks to whether your system recognizes the specified layer and option. If so, then can you set the retrieved value on the socket you read it from? That speaks to whether the specific value you are trying to set for the option may be the issue.setsockopt()is probably just the messenger. I guess this could be a manifestation of some kind of security measure, but I haven't found any documentation to support that (or any other) explanation.