---
name: "socket_sendfile"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.10-1"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/socket_sendfile"
---

# socket\_sendfile(3)

send a file over a TCP socket

## NAME

socket\_sendfile - send a file over a TCP socket

## SYNTAX

**#include \<socket.h\>**

int **socket\_sendfile**(int *out*, int *in*, uint32 *offset*,\
                     uint32 *bytes*);

## DESCRIPTION

socket\_sendfile sends *bytes* bytes starting at *offset* in the file *in* to the socket connected to file descriptor *out*.

The socket must be connected.

Note that the underlying sendfile system call is system specific and currently only implemented on Linux.  On other operating systems, it is emulated with a read/write loop.

## RETURN VALUE

socket\_sendfile returns 0 if the data was sent successfully.  If not, it returns -1 and sets errno appropriately.

## EXAMPLE

  \#include \<socket.h\>\
   \#include \<open.h\>

  int *s*;\
   char *ip*\[4\];\
   uint16 *p*;\
   int *fd* = open\_read("/etc/passwd");

  *s* = socket\_tcp4();\
   socket\_connect4(s,ip,p);\
   socket\_sendfile(s,fd,0,23);

## SEE ALSO

[socket\_send6(3)](/socket_send6/3.md)
