<p>When I create a socket using accept() and make a FILE out of it using fdopen(), what do I have to do to clean everything up? Do I need to do fclose() on the FILE, shutdown() and close() on the socket, or only the shutdown() and or close() or fclose()? If I don't do fclose(), do I have to free() the FILE pointer manually?</p>

You have 2 things here you need to clean up: the stream represented by
```
FILE
```
and the file descriptor represented by the socket. You need to close the stream first, then the file descriptor. So, in general you will need to
```
fclose()
```
any
```
FILE
```
objects, then
```
close()
```
any file descriptors.
Personally I have never used
```
shutdown()
```
when I want to cleanup after myself, so I can't say.
edit
Others have correctly pointed out that
```
fdclose()
```
will also close the underlying file descriptor, and since calling
```
close()
```
on a close file descriptor will lead to an error, in this case you only need
```
fdclose()
```
.