This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ safe include files


I've noticed that a handful of functions within the networking package
appear to not have the correct type-linkage when compiling C++ programs
(i.e. they are declared as extern - C++ linkage, when the actual routines
are C linkage).

I've attached a patch that inserts the 'externC', or 'extern "C" {'
constructions into the relevant place in the header files.

Additionally, the (empty) function getservbynumber() is present, whilst
the header file refers to the (correct) getservbyport() function. This has
also been corrected in the patch.

-- 
Richard Panton              Systems Architect          3G Lab Ltd.
richard.panton@3glab.com    http://www.3glab.org/
Index: net/tcpip/current/include/bootp.h
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/tcpip/current/include/bootp.h,v
retrieving revision 1.6
diff -u -p -r1.6 bootp.h
--- bootp.h	2000/07/17 14:42:32	1.6
+++ bootp.h	2001/03/28 15:48:31
@@ -346,7 +346,7 @@ extern const char  *eth1_name;
 // ------------------------------------------------------------------------
 // Initialize your own bootp record however you like, as far as is needed
 // to bring up an interface.
-extern void
+externC void
 build_bootp_record(struct bootp *bp,
                    const char *addrs_ip,
                    const char *addrs_netmask,
@@ -357,29 +357,29 @@ build_bootp_record(struct bootp *bp,
 // Do bootp to fill in the bootp record from the net (other interfaces must
 // be down for this to work, because of the "half-up" state of the
 // interface in use)
-extern cyg_bool_t do_bootp(const char *interface, struct bootp *res);
+externC cyg_bool_t do_bootp(const char *interface, struct bootp *res);
 
 // Initialize an interface (which is down) according to a bootp structure
-extern cyg_bool_t init_net(const char *interface, struct bootp *res);
+externC cyg_bool_t init_net(const char *interface, struct bootp *res);
 
 // Dump contents to diag_printf
-extern void show_bootp(const char *interface, struct bootp *res);
+externC void show_bootp(const char *interface, struct bootp *res);
 
 // Interrogate a bootp record for a particular option
-extern cyg_bool_t get_bootp_option(struct bootp *bp, unsigned char tag, void *res);
+externC cyg_bool_t get_bootp_option(struct bootp *bp, unsigned char tag, void *res);
 
 // ------------------------------------------------------------------------
 // This isn't exactly the right place for this since bootp is not involved
 // BUT you will only be using this API if you are using bootp-style
 // initialization of the other interfaces; it fits here in a documentation
 // sense.
-extern cyg_bool_t init_loopback_interface(int lo);
+externC cyg_bool_t init_loopback_interface(int lo);
 
 // ------------------------------------------------------------------------
 // Do all the above automatically according to the configuration.  Do not
 // mix using this and making the above calls yourself.
 // (this is also declared in the much simpler API in network.h)
-extern void init_all_network_interfaces(void);
+externC void init_all_network_interfaces(void);
 
 #endif
 
Index: net/tcpip/current/include/netdb.h
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/tcpip/current/include/netdb.h,v
retrieving revision 1.1
diff -u -p -r1.1 netdb.h
--- netdb.h	2000/06/06 08:39:39	1.1
+++ netdb.h	2001/03/28 15:48:31
@@ -59,6 +59,10 @@
 #ifndef _NETDB_H_
 #define _NETDB_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 // Internet protocols
 struct protoent {
     char *p_name;
@@ -92,4 +96,7 @@ struct hostent {
 struct hostent *gethostbyname(const char *host);
 struct hostent *gethostbyaddr(const char *addr, int len, int type);
 
+#ifdef __cplusplus
+}
+#endif
 #endif // _NETDB_H_
Index: net/tcpip/current/include/network.h
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/tcpip/current/include/network.h,v
retrieving revision 1.3
diff -u -p -r1.3 network.h
--- network.h	2000/11/17 23:16:44	1.3
+++ network.h	2001/03/28 15:48:31
@@ -88,15 +88,15 @@ extern cyg_bool_t   eth1_up;
 extern const char  *eth1_name;
 #endif
 
-extern void init_all_network_interfaces(void);
+externC void init_all_network_interfaces(void);
 
-extern void     route_reinit(void);
-extern void     perror(const char *);
-extern int      close(int);
-extern ssize_t  read(int, void *, size_t);
-extern ssize_t  write(int, const void *, size_t);
-extern char     *inet_ntoa(struct in_addr);
-extern int      select(int, fd_set *, fd_set *, fd_set *, struct timeval *tv);
+externC void     route_reinit(void);
+externC void     perror(const char *);
+externC int      close(int);
+externC ssize_t  read(int, void *, size_t);
+externC ssize_t  write(int, const void *, size_t);
+externC char     *inet_ntoa(struct in_addr);
+externC int      select(int, fd_set *, fd_set *, fd_set *, struct timeval *tv);
 
 // This API is for our own automated network tests.
 // It's not at all supported.
Index: net/tcpip/current/include/tftp_support.h
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/tcpip/current/include/tftp_support.h,v
retrieving revision 1.2
diff -u -p -r1.2 tftp_support.h
--- tftp_support.h	2000/10/12 20:31:52	1.2
+++ tftp_support.h	2001/03/28 15:48:31
@@ -97,15 +97,15 @@ struct tftpd_fileops {
 #define O_WRONLY 2
 #endif
 
-extern int tftpd_start(int, struct tftpd_fileops *);
-extern int tftpd_stop(int);
+externC int tftpd_start(int, struct tftpd_fileops *);
+externC int tftpd_stop(int);
 
 /*
  * Client support
  */
 
-extern int tftp_get(char *, struct sockaddr_in *, char *, int, int, int *);
-extern int tftp_put(char *, struct sockaddr_in *, char *, int, int, int *);
+externC int tftp_get(char *, struct sockaddr_in *, char *, int, int, int *);
+externC int tftp_put(char *, struct sockaddr_in *, char *, int, int, int *);
 
 #define TFTP_TIMEOUT_PERIOD  5          // Seconds between retries
 #define TFTP_TIMEOUT_MAX    50          // Max timeouts over all blocks
Index: net/tcpip/current/src/lib/getserv.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/tcpip/current/src/lib/getserv.c,v
retrieving revision 1.2
diff -u -p -r1.2 getserv.c
--- getserv.c	2000/08/25 17:33:45	1.2
+++ getserv.c	2001/03/28 15:48:31
@@ -79,7 +79,7 @@ getservbyname(const char *name, const ch
 }
 
 struct servent *
-getservbynumber(const int num, const char *proto)
+getservbyport(const int num, const char *proto)
 {
     struct servent *p = services;
     while (p->s_name) {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]