<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>Sockets</TITLE
|
>Sockets</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="File System Support Infrastructure"
|
TITLE="File System Support Infrastructure"
|
HREF="fileio.html"><LINK
|
HREF="fileio.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="Initialization and Mounting"
|
TITLE="Initialization and Mounting"
|
HREF="fileio-mounting.html"><LINK
|
HREF="fileio-mounting.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="Select"
|
TITLE="Select"
|
HREF="fileio-select.html"></HEAD
|
HREF="fileio-select.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="fileio-mounting.html"
|
HREF="fileio-mounting.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="fileio-select.html"
|
HREF="fileio-select.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
><H1
|
><H1
|
><A
|
><A
|
NAME="FILEIO-SOCKETS">Chapter 26. Sockets</H1
|
NAME="FILEIO-SOCKETS">Chapter 26. Sockets</H1
|
><P
|
><P
|
>If a network stack is present, then the FILEIO infrastructure also
|
>If a network stack is present, then the FILEIO infrastructure also
|
provides access to the standard BSD socket calls.</P
|
provides access to the standard BSD socket calls.</P
|
><P
|
><P
|
>The netstack table contains entries which describe the network
|
>The netstack table contains entries which describe the network
|
protocol stacks that are in the system image. Each resident stack
|
protocol stacks that are in the system image. Each resident stack
|
should export an entry to this table using the
|
should export an entry to this table using the
|
<TT
|
<TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>NSTAB_ENTRY()</TT
|
>NSTAB_ENTRY()</TT
|
> macro.</P
|
> macro.</P
|
><P
|
><P
|
>Each table entry has the following structure:</P
|
>Each table entry has the following structure:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>struct cyg_nstab_entry
|
>struct cyg_nstab_entry
|
{
|
{
|
cyg_bool valid; // true if stack initialized
|
cyg_bool valid; // true if stack initialized
|
cyg_uint32 syncmode; // synchronization protocol
|
cyg_uint32 syncmode; // synchronization protocol
|
char *name; // stack name
|
char *name; // stack name
|
char *devname; // hardware device name
|
char *devname; // hardware device name
|
CYG_ADDRWORD data; // private data value
|
CYG_ADDRWORD data; // private data value
|
|
|
int (*init)( cyg_nstab_entry *nste );
|
int (*init)( cyg_nstab_entry *nste );
|
int (*socket)( cyg_nstab_entry *nste, int domain, int type,
|
int (*socket)( cyg_nstab_entry *nste, int domain, int type,
|
int protocol, cyg_file *file );
|
int protocol, cyg_file *file );
|
};</PRE
|
};</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>This table is analogous to a combination of the filesystem and mount
|
>This table is analogous to a combination of the filesystem and mount
|
tables.</P
|
tables.</P
|
><P
|
><P
|
>The <TT
|
>The <TT
|
CLASS="STRUCTFIELD"
|
CLASS="STRUCTFIELD"
|
><I
|
><I
|
>valid</I
|
>valid</I
|
></TT
|
></TT
|
> field is set
|
> field is set
|
<TT
|
<TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>true</TT
|
>true</TT
|
> if the stack's <TT
|
> if the stack's <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>init()</TT
|
>init()</TT
|
>
|
>
|
function returned successfully and the
|
function returned successfully and the
|
<TT
|
<TT
|
CLASS="STRUCTFIELD"
|
CLASS="STRUCTFIELD"
|
><I
|
><I
|
>syncmode</I
|
>syncmode</I
|
></TT
|
></TT
|
> field contains the
|
> field contains the
|
<TT
|
<TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>CYG_SYNCMODE_SOCK_*</TT
|
>CYG_SYNCMODE_SOCK_*</TT
|
> bits described above.</P
|
> bits described above.</P
|
><P
|
><P
|
>The <TT
|
>The <TT
|
CLASS="STRUCTFIELD"
|
CLASS="STRUCTFIELD"
|
><I
|
><I
|
>name</I
|
>name</I
|
></TT
|
></TT
|
> field contains the name of the
|
> field contains the name of the
|
protocol stack.</P
|
protocol stack.</P
|
><P
|
><P
|
>The <TT
|
>The <TT
|
CLASS="STRUCTFIELD"
|
CLASS="STRUCTFIELD"
|
><I
|
><I
|
>devname</I
|
>devname</I
|
></TT
|
></TT
|
> field names the device that the stack is using. This may
|
> field names the device that the stack is using. This may
|
reference a device under "/dev", or may be a name that is only
|
reference a device under "/dev", or may be a name that is only
|
meaningful to the stack itself.</P
|
meaningful to the stack itself.</P
|
><P
|
><P
|
>The <TT
|
>The <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>init()</TT
|
>init()</TT
|
> function pointer is called during
|
> function pointer is called during
|
system initialization to start the protocol stack running. If it
|
system initialization to start the protocol stack running. If it
|
returns non-zero the <TT
|
returns non-zero the <TT
|
CLASS="STRUCTFIELD"
|
CLASS="STRUCTFIELD"
|
><I
|
><I
|
>valid</I
|
>valid</I
|
></TT
|
></TT
|
> field is set
|
> field is set
|
false and the stack will be ignored subsequently.</P
|
false and the stack will be ignored subsequently.</P
|
><P
|
><P
|
>The <TT
|
>The <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>socket()</TT
|
>socket()</TT
|
> function is called to attempt to create a socket in the
|
> function is called to attempt to create a socket in the
|
stack. When the <TT
|
stack. When the <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>socket()</TT
|
>socket()</TT
|
> API function is called the netstack table is
|
> API function is called the netstack table is
|
scanned and for each valid entry the <TT
|
scanned and for each valid entry the <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>socket()</TT
|
>socket()</TT
|
>
|
>
|
function pointer is called. If
|
function pointer is called. If
|
this returns non-zero then the scan continues to the next valid stack,
|
this returns non-zero then the scan continues to the next valid stack,
|
or terminates with an error if the end of the table is reached.</P
|
or terminates with an error if the end of the table is reached.</P
|
><P
|
><P
|
>The result of a successful socket call is an initialized file object
|
>The result of a successful socket call is an initialized file object
|
with the <TT
|
with the <TT
|
CLASS="STRUCTFIELD"
|
CLASS="STRUCTFIELD"
|
><I
|
><I
|
>f_xops</I
|
>f_xops</I
|
></TT
|
></TT
|
> field pointing to the
|
> field pointing to the
|
following structure:</P
|
following structure:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>struct cyg_sock_ops
|
>struct cyg_sock_ops
|
{
|
{
|
int (*bind) ( cyg_file *fp, const sockaddr *sa, socklen_t len );
|
int (*bind) ( cyg_file *fp, const sockaddr *sa, socklen_t len );
|
int (*connect) ( cyg_file *fp, const sockaddr *sa, socklen_t len );
|
int (*connect) ( cyg_file *fp, const sockaddr *sa, socklen_t len );
|
int (*accept) ( cyg_file *fp, cyg_file *new_fp,
|
int (*accept) ( cyg_file *fp, cyg_file *new_fp,
|
struct sockaddr *name, socklen_t *anamelen );
|
struct sockaddr *name, socklen_t *anamelen );
|
int (*listen) ( cyg_file *fp, int len );
|
int (*listen) ( cyg_file *fp, int len );
|
int (*getname) ( cyg_file *fp, sockaddr *sa, socklen_t *len, int peer );
|
int (*getname) ( cyg_file *fp, sockaddr *sa, socklen_t *len, int peer );
|
int (*shutdown) ( cyg_file *fp, int flags );
|
int (*shutdown) ( cyg_file *fp, int flags );
|
int (*getsockopt)( cyg_file *fp, int level, int optname,
|
int (*getsockopt)( cyg_file *fp, int level, int optname,
|
void *optval, socklen_t *optlen);
|
void *optval, socklen_t *optlen);
|
int (*setsockopt)( cyg_file *fp, int level, int optname,
|
int (*setsockopt)( cyg_file *fp, int level, int optname,
|
const void *optval, socklen_t optlen);
|
const void *optval, socklen_t optlen);
|
int (*sendmsg) ( cyg_file *fp, const struct msghdr *m,
|
int (*sendmsg) ( cyg_file *fp, const struct msghdr *m,
|
int flags, ssize_t *retsize );
|
int flags, ssize_t *retsize );
|
int (*recvmsg) ( cyg_file *fp, struct msghdr *m,
|
int (*recvmsg) ( cyg_file *fp, struct msghdr *m,
|
socklen_t *namelen, ssize_t *retsize );
|
socklen_t *namelen, ssize_t *retsize );
|
};</PRE
|
};</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>It should be obvious from the names of these functions which API calls
|
>It should be obvious from the names of these functions which API calls
|
they provide support for. The <TT
|
they provide support for. The <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>getname()</TT
|
>getname()</TT
|
> function
|
> function
|
pointer provides support for both <TT
|
pointer provides support for both <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>getsockname()</TT
|
>getsockname()</TT
|
>
|
>
|
and <TT
|
and <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>getpeername()</TT
|
>getpeername()</TT
|
> while the
|
> while the
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>sendmsg()</TT
|
>sendmsg()</TT
|
> and <TT
|
> and <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>recvmsg()</TT
|
>recvmsg()</TT
|
>
|
>
|
function pointers provide support for <TT
|
function pointers provide support for <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>send()</TT
|
>send()</TT
|
>,
|
>,
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>sendto()</TT
|
>sendto()</TT
|
>, <TT
|
>, <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>sendmsg()</TT
|
>sendmsg()</TT
|
>,
|
>,
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>recv()</TT
|
>recv()</TT
|
>, <TT
|
>, <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>recvfrom()</TT
|
>recvfrom()</TT
|
> and
|
> and
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>recvmsg()</TT
|
>recvmsg()</TT
|
> as appropriate.</P
|
> as appropriate.</P
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="fileio-mounting.html"
|
HREF="fileio-mounting.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="fileio-select.html"
|
HREF="fileio-select.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>Initialization and Mounting</TD
|
>Initialization and Mounting</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="fileio.html"
|
HREF="fileio.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>Select</TD
|
>Select</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|