libnl 3.0
|
00001 /* 00002 * lib/error.c Error Handling 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation version 2.1 00007 * of the License. 00008 * 00009 * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 #include <netlink-local.h> 00013 #include <netlink/netlink.h> 00014 00015 static const char *errmsg[NLE_MAX+1] = { 00016 [NLE_SUCCESS] = "Success", 00017 [NLE_FAILURE] = "Unspecific failure", 00018 [NLE_INTR] = "Interrupted system call", 00019 [NLE_BAD_SOCK] = "Bad socket", 00020 [NLE_AGAIN] = "Try again", 00021 [NLE_NOMEM] = "Out of memory", 00022 [NLE_EXIST] = "Object exists", 00023 [NLE_INVAL] = "Invalid input data or parameter", 00024 [NLE_RANGE] = "Input data out of range", 00025 [NLE_MSGSIZE] = "Message size not sufficient", 00026 [NLE_OPNOTSUPP] = "Operation not supported", 00027 [NLE_AF_NOSUPPORT] = "Address family not supported", 00028 [NLE_OBJ_NOTFOUND] = "Object not found", 00029 [NLE_NOATTR] = "Attribute not available", 00030 [NLE_MISSING_ATTR] = "Missing attribute", 00031 [NLE_AF_MISMATCH] = "Address family mismatch", 00032 [NLE_SEQ_MISMATCH] = "Message sequence number mismatch", 00033 [NLE_MSG_OVERFLOW] = "Kernel reported message overflow", 00034 [NLE_MSG_TRUNC] = "Kernel reported truncated message", 00035 [NLE_NOADDR] = "Invalid address for specified address family", 00036 [NLE_SRCRT_NOSUPPORT] = "Source based routing not supported", 00037 [NLE_MSG_TOOSHORT] = "Netlink message is too short", 00038 [NLE_MSGTYPE_NOSUPPORT] = "Netlink message type is not supported", 00039 [NLE_OBJ_MISMATCH] = "Object type does not match cache", 00040 [NLE_NOCACHE] = "Unknown or invalid cache type", 00041 [NLE_BUSY] = "Object busy", 00042 [NLE_PROTO_MISMATCH] = "Protocol mismatch", 00043 [NLE_NOACCESS] = "No Access", 00044 [NLE_PERM] = "Operation not permitted", 00045 [NLE_PKTLOC_FILE] = "Unable to open packet location file", 00046 [NLE_PARSE_ERR] = "Unable to parse object", 00047 }; 00048 00049 /** 00050 * Return error message for an error code 00051 * @return error message 00052 */ 00053 const char *nl_geterror(int error) 00054 { 00055 error = abs(error); 00056 00057 if (error > NLE_MAX) 00058 error = NLE_FAILURE; 00059 00060 return errmsg[error]; 00061 } 00062 00063 /** 00064 * Print a libnl error message 00065 * @arg s error message prefix 00066 * 00067 * Prints the error message of the call that failed last. 00068 * 00069 * If s is not NULL and *s is not a null byte the argument 00070 * string is printed, followed by a colon and a blank. Then 00071 * the error message and a new-line. 00072 */ 00073 void nl_perror(int error, const char *s) 00074 { 00075 if (s && *s) 00076 fprintf(stderr, "%s: %s\n", s, nl_geterror(error)); 00077 else 00078 fprintf(stderr, "%s\n", nl_geterror(error)); 00079 } 00080 00081 int nl_syserr2nlerr(int error) 00082 { 00083 error = abs(error); 00084 00085 switch (error) { 00086 case EBADF: return NLE_BAD_SOCK; 00087 case EADDRINUSE: return NLE_EXIST; 00088 case EEXIST: return NLE_EXIST; 00089 case EADDRNOTAVAIL: return NLE_NOADDR; 00090 case ENOENT: return NLE_OBJ_NOTFOUND; 00091 case EINTR: return NLE_INTR; 00092 case EAGAIN: return NLE_AGAIN; 00093 case ENOTSOCK: return NLE_BAD_SOCK; 00094 case ENOPROTOOPT: return NLE_INVAL; 00095 case EFAULT: return NLE_INVAL; 00096 case EACCES: return NLE_NOACCESS; 00097 case EINVAL: return NLE_INVAL; 00098 case ENOBUFS: return NLE_NOMEM; 00099 case ENOMEM: return NLE_NOMEM; 00100 case EAFNOSUPPORT: return NLE_AF_NOSUPPORT; 00101 case EPROTONOSUPPORT: return NLE_PROTO_MISMATCH; 00102 case EOPNOTSUPP: return NLE_OPNOTSUPP; 00103 case EPERM: return NLE_PERM; 00104 case EBUSY: return NLE_BUSY; 00105 case ERANGE: return NLE_RANGE; 00106 default: return NLE_FAILURE; 00107 } 00108 } 00109 00110 /** @} */ 00111