One normally closes a socket by calling close(). But what if you want to reset / abort the connection (RST packet)? How do you send it from userland?
If I recall, you set the SO_LINGER option.
struct linger l;
l.l_onoff = 1;
l.l_linger = 0;
setsockopt(sock, SOL_SOCKET, SO_LINGER, &l, sizeof(l));