---
name: "brlapi_packetType"
section: "3"
platform: "linux"
package: "libbrlapi1-dev"
version: "3.7.2-7.1"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/brlapi_error"
---

# brlapi\_packetType(3)

How to handle errors which might very well happen.

Part of [brlapi\_error(3)](/brlapi_error/3.md).

## NAME

Error handling - How to handle errors which might very well happen.

### Data Structures

struct **brlapi\_error\_t**\

### Defines

\#define **BRLERR\_SUCCESS**   0\
 \#define **BRLERR\_NOMEM**   1\
 \#define **BRLERR\_TTYBUSY**   2\
 \#define **BRLERR\_RAWMODEBUSY**   3\
 \#define **BRLERR\_UNKNOWN\_INSTRUCTION**   4\
 \#define **BRLERR\_ILLEGAL\_INSTRUCTION**   5\
 \#define **BRLERR\_INVALID\_PARAMETER**   6\
 \#define **BRLERR\_INVALID\_PACKET**   7\
 \#define **BRLERR\_CONNREFUSED**   8\
 \#define **BRLERR\_OPNOTSUPP**   9\
 \#define **BRLERR\_GAIERR**   10\
 \#define **BRLERR\_LIBCERR**   11\
 \#define **BRLERR\_UNKNOWNTTY**   12\
 \#define **BRLERR\_PROTOCOL\_VERSION**   13\
 \#define **BRLERR\_EOF**   14\
 \#define **BRLERR\_EMPTYKEY**   15\
 \#define **BRLERR\_DRIVERERROR**   16\
 \#define **brlapi\_error**   (\*brlapi\_error\_location())\
 \#define **brlapi\_errno**   (brlapi\_error.brlerrno)\
 \#define **brlapi\_libcerrno**   (brlapi\_error.exterrno.libcerrno)\
 \#define **brlapi\_gaierrno**   (brlapi\_error.exterrno.gaierrno)\
 \#define **brlapi\_errfun**   (brlapi\_error.errfun)\

### Typedefs

typedef uint32\_t **brl\_type\_t**\
 typedef void(\* **brlapi\_exceptionHandler\_t** )(int err, **brl\_type\_t** type, const void \*buf, size\_t size)\

### Functions

void **brlapi\_perror** (const char \*s)\
 **brlapi\_error\_t** \* **brlapi\_error\_location** (void)\
 const char \* **brlapi\_strerror** (const **brlapi\_error\_t** \*error)\
 const char \* **brlapi\_packetType** (**brl\_type\_t** ptype)\
 int **brlapi\_strexception** (char \*buf, size\_t n, int err, **brl\_type\_t** type, const void \*packet, size\_t size)\
 **brlapi\_exceptionHandler\_t** **brlapi\_setExceptionHandler** (**brlapi\_exceptionHandler\_t** handler)\

### Variables

const char \* **brlapi\_errlist** \[\]\
 const int **brlapi\_nerr**\
 **brlapi\_error\_t** **brlapi\_error**\
 int **brlapi\_errno**\
 int **brlapi\_libcerrno**\
 int **brlapi\_gaierrno**\
 const char \* **brlapi\_errfun**\

## Detailed Description

When a function fails for some normal error, brlapi\_errno will hold an error code to explain why it failed. It is good practice to print it somewhere for the user or the programmer to understand why it failed.

When something really wrong was done somewhere, like an out-of-bounds argument, which is really a bug in either the implementation of BrlAPI or in the application, an exception may be sent by the server. As soon as libbrlapi receives it, an exception handler prints it and *abort()s* he program, since it means something went really wrong and that we shouldn't go further.

This is hopefully a really seldom event, but in the case of an editor, for instance, one would surely want to have files saved before actually abort()ing. **brlapi\_setExceptionHandler()** lets the programmer define another exception handler which would save files and then call the default handler brlapi\_defaultExceptionHandler().

## Define Documentation

### #define brlapi\_errfun (brlapi\_error.errfun)

Cheat about the brlapi\_errfun C token

### #define brlapi\_errno (brlapi\_error.brlerrno)

Cheat about the brlapi\_errno C token

### #define brlapi\_error (\*brlapi\_error\_location())

Cheat about the brlapi\_error C token

### #define brlapi\_gaierrno (brlapi\_error.exterrno.gaierrno)

Cheat about the brlapi\_gaierrno C token

### #define brlapi\_libcerrno (brlapi\_error.exterrno.libcerrno)

Cheat about the brlapi\_libcerrno C token

### #define BRLERR\_CONNREFUSED 8

Connection refused

### #define BRLERR\_DRIVERERROR 16

Packet returned by driver too large

### #define BRLERR\_EMPTYKEY 15

Key file empty

### #define BRLERR\_EOF 14

Unexpected end of file

### #define BRLERR\_GAIERR 10

Getaddrinfo error

### #define BRLERR\_ILLEGAL\_INSTRUCTION 5

Forbiden in current mode

### #define BRLERR\_INVALID\_PACKET 7

Invalid size

### #define BRLERR\_INVALID\_PARAMETER 6

Out of range or have no sense

### #define BRLERR\_LIBCERR 11

Libc error

### #define BRLERR\_NOMEM 1

Not enough memory

### #define BRLERR\_OPNOTSUPP 9

Operation not supported

### #define BRLERR\_PROTOCOL\_VERSION 13

Bad protocol version

### #define BRLERR\_RAWMODEBUSY 3

A connection is already using RAW mode

### #define BRLERR\_SUCCESS 0

Success

### #define BRLERR\_TTYBUSY 2

A connection is already running in this tty

### #define BRLERR\_UNKNOWN\_INSTRUCTION 4

Not implemented in protocol

### #define BRLERR\_UNKNOWNTTY 12

Couldn't find out the tty number

## Typedef Documentation

### typedef uint32\_t brl\_type\_t

Type for packet type. Only unsigned can cross networks, 32bits

### typedef void(\* brlapi\_exceptionHandler\_t)(int err, brl\_type\_t type, const void \*buf, size\_t size)

Type for error handlers

Type of error handlers which are to be given to **brlapi\_setExceptionHandler()**.

**Parameters:**

*err* is a BRLERR\_ error code; \
 *type* is the type of the guilty packet; \
 *buf* points to the content of the guilty packet (might be a little bit truncated); \
 *size* gives the guilty packet's size.

## Function Documentation

### brlapi\_error\_t\* brlapi\_error\_location (void)

Get per-thread error location

In multithreaded software, brlapi\_error is thread-specific, so **api.h** cheats about the brlapi\_error token and actually calls **brlapi\_error\_location()**.

This gets the thread specific location of global variable brlapi\_error

### const char\* brlapi\_packetType (brl\_type\_t ptype)

Get plain packet type

**brlapi\_packetType()** returns the plain packet type name corresponding to its argument.

### void brlapi\_perror (const char \* s)

Print a BrlAPI error message

**brlapi\_perror()** reads brlapi\_error, and acts just like perror().

### brlapi\_exceptionHandler\_t brlapi\_setExceptionHandler (brlapi\_exceptionHandler\_t handler)

Set a new exception handler

**brlapi\_setExceptionHandler()** replaces the previous exception handler with the handler parameter. The previous exception handler is returned to make chaining error handlers possible.

The default handler just prints the exception and exit()s.

### const char\* brlapi\_strerror (const brlapi\_error\_t \* error)

Get plain error message

**brlapi\_strerror()** returns the plain error message corresponding to its argument.

### int brlapi\_strexception (char \* buf, size\_t n, int err, brl\_type\_t type, const void \* packet, size\_t size)

Describes an exception

**brlapi\_strexception()** puts a text describing the given exception in buf.

The beginning of the guilty packet is dumped as a sequence of hex bytes.

**Returns:**

the size of the text describing the exception, following snprintf()'s semantics.

## Variable Documentation

### const char\* brlapi\_errfun

Shorthand for brlapi\_error.errfun

### const char\* brlapi\_errlist\[\]

Error message list

These are the string constants used by **brlapi\_perror()**.

### int brlapi\_errno

Shorthand for brlapi\_error.errno

### brlapi\_error\_t brlapi\_error

Global variable brlapi\_error

brlapi\_error is a global left-value containing the last error information. Its errno field is not reset to BRLERR\_SUCCESS on success.

This information may be copied in **brlapi\_error\_t** variables for later use with the brlapi\_strerror function.

### int brlapi\_gaierrno

Shorthand for brlapi\_error.exterrno.gaierrno

### int brlapi\_libcerrno

Shorthand for brlapi\_error.exterrno.libcerrno

### const int brlapi\_nerr

Number of error messages
